/*! \file InputLayoutDesc.cpp
 *	\brief 
 *
 *	created:	2010/12/08
 *	created:	8:12:2010   15:43
 *	filename: 	C:\src\tactics-engine\libs\gd\InputLayoutDesc.cpp
 *	file path:	C:\src\tactics-engine\libs\gd
 *	file base:	InputLayoutDesc
 *	file ext:	cpp
 *	author:		Vitalii Trubchaninov
 *				vitalii.trubchaninov@ubisoft.com
 */

#include "gd/stdafx.h"
#include "gd/InputLayoutDesc.h"

namespace tt{
namespace gd{

const Char* const IL_ELEMENT_TAG = "Element";
const Char* const IL_SEMANTIC_TAG = "Semantic";
const Char* const IL_SEMANTIC_INDEX_TAG = "SemanticIndex";
const Char* const IL_FORMAT_TAG = "DXGIFormat";

//////////////////////////////////////////////////////////////////////////
InputLayoutDescElement::InputLayoutDescElement()
: semantic()
, semanticIndex(0)
, format()
{

}

//////////////////////////////////////////////////////////////////////////
InputLayoutDesc::InputLayoutDesc()
{

}

bool InputLayoutDesc::Create( const utils::PTree& in )
{
	using utils::PTree;

	InputLayoutDescElement desc;
	for(utils::PTree::const_iterator element_it = in.begin(); element_it != in.end(); ++element_it)
	{
		if(element_it->first != IL_ELEMENT_TAG)
			return false;

		const utils::PTree& element = element_it->second;

		desc.semantic = element.get<String>(IL_SEMANTIC_TAG);
		desc.semanticIndex = element.get<UInt>(IL_SEMANTIC_INDEX_TAG, 0);
		desc.format = element.get<String>(IL_FORMAT_TAG);

		m_elements.push_back(desc);
	}

	return true;
}

const InputLayoutDescElements& InputLayoutDesc::elements() const
{
	return m_elements;
}

} //namespace gd
} //namespace tt
